package com.ftg.learn.annotationforme.mapper;

import com.ftg.learn.annotationforme.entity.ShopProductEntity;
import com.ftg.learn.annotationforme.provider.ShopProductProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 描述
 *  完成对表shop_product的相关功能
 * @author 布衣
 * @date 2025/10/15
 */
public interface ShopProductMapper {


    @Select("select p.id,\n" +
            "       pro_name proName,\n" +
            "       pro_price proPrice,\n" +
            "       pro_desc,\n" +
            "       pro_status,\n" +
            "       case\n" +
            "           when pro_type = 0 then '瓶装'\n" +
            "           when pro_type = 1 then '桶装'\n" +
            "           when pro_type = 2 then '箱'\n" +
            "           else '其它'\n" +
            "           end  proType,\n" +
            "       pro_num\n" +
            "from shop_product p\n" +
            "    join shop_category sc\n" +
            "       on p.pro_category_id = sc.id")
    List<ShopProductEntity> showAll();

    @SelectProvider(type = ShopProductProvider.class,method = "listByProName")
    List<ShopProductEntity> listByProName(@Param("proName") String proName);



    @Insert("insert into shop_product(pro_name,pro_price,pro_desc,pro_status,pro_type,pro_num) " +
            "values(#{proName},#{proPrice},#{proDesc},#{proStatus},#{proType},#{proNum})")
    int saveShopProduct(ShopProductEntity se);

    @Update("update shop_product set pro_name=#{proName}" +
            ",pro_price=#{proPrice},pro_desc=#{proDesc}," +
            "pro_status=#{proStatus},pro_type=#{proType}" +
            ",pro_num=#{proNum} " +
            "where id=#{id}")
    int modifyShopProduct(ShopProductEntity se);

    @Delete("delete from shop_product where id=#{id}")
    int deleteShopProduct(Integer id);


}
